public class Solution2470 {
    public int subarrayLCM(int[] nums, int k) {
        int ans=0;
        for (int i=0;i<nums.length;i++){
            int j=i,start=nums[i];
            while (start<k){
                j++;
                if (j>=nums.length){
                    break;
                }
                start=lcm(start,nums[j]);
            }
            while (start==k){
                ans++;
                j++;
                if (j>=nums.length){
                    break;
                }
                start=lcm(start,nums[j]);
            }
        }
        return ans;
    }

    private int lcm(int a, int b) {
        return a*b/gcd(a,b);
    }

    private int gcd(int a, int b) {
        if (a<b){
            int t=a;
            a=b;
            b=t;
        }
        return a%b==0?b:gcd(b,a%b);
    }

    public static void main(String[] args) {
        System.out.println(new Solution2470().subarrayLCM(new int[]{3,6,2,7,1},6));
    }
}
